package com.api.shopapi.mapper;

import com.api.shopapi.entity.ElderlyClockinMonth;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface ElderlyClockinMonthMapper {


    @Insert("insert into elderly_clockin_month " +
            "(" +
            "ElderlyClockinMonthCode," +
            "ElderlyCode," +
            "Month" +
            ") " +
            "value " +
            "(" +
            "#{elderlyClockinMonth.ElderlyClockinMonthCode}," +
            "#{elderlyClockinMonth.ElderlyCode}," +
            "#{elderlyClockinMonth.Month})")
    int insert(@Param("elderlyClockinMonth") ElderlyClockinMonth elderlyClockinMonth);

    @Insert("<script>" +
            "insert into elderly_clockin_month (ElderlyClockinMonthCode,ElderlyCode,Month) values " +
            "<foreach collection='list' item='obj' separator=','>" +
            "(#{obj.ElderlyClockinMonthCode},#{obj.ElderlyCode},#{obj.Month})" +
            "</foreach>" +
            "</script>")
    Integer batchInsert(List<ElderlyClockinMonth> list);

    @Select("select * from elderly_clockin_month where elderlyCode=#{elderlyCode} and month=#{month} limit 1 ")
    ElderlyClockinMonth getByElderlyCodeMonth(@Param("elderlyCode") String elderlyCode,
                                              @Param("month") Date month);


    @Select("select * from elderly_clockin_month where " +
            " elderlyCode = #{elderlyCode} " +
            " order by month desc")
    List<ElderlyClockinMonth> getListByElderlyCode(@Param("elderlyCode")String elderlyCode);


}
